#!/bin/sh

# takes input from clamscan -i

grep ^/ |grep FOUND |while read file clam
do
  file=`echo $file |sed -e 's/:$//'`
  basename=`basename $file`
  dirname=`dirname $file`
  arcfile=`basename $dirname`
  case "$file" in
    */msg*.html)
      msgid=`grep -i X-Message-Id $file |awk '{print $2}'`
      ;;
    */author.html|*/maillist.html|*/subject.html|*/threads.html)
#      echo meta $file
      ;;
    *)
#      echo bin $file
      file=`grep -lr $basename $dirname |grep .html$`
      msgid=`grep -i X-Message-Id $file |awk '{print $2}'`
      basename=`basename $file`
      dirname=`dirname $file`
      arcfile=`basename $dirname`
      ;;
  esac
  echo `echo $msgid |sed -e 's/\&#45\;/-/g' -e 's/^/Skip-Spam-Message-Id: </' -e 's/$/>/'` $clam >> /org/lists.debian.org/archive-spam-removals/spam-removals/clam-removals/$arcfile.spam
done
